package com.upcode.weighing.util;

import java.math.BigDecimal;
import java.util.Random;
import java.util.UUID;

public class NumberUtil {
    public static double halfUp(double val,int scale){
        BigDecimal b   =   new   BigDecimal(val);
        double  f1   =   b.setScale(scale,   BigDecimal.ROUND_HALF_UP).doubleValue();
        return f1;
    }

    public static String halfUpStr(double val,int scale){
        BigDecimal b   =   new   BigDecimal(val);
        double  f1   =   b.setScale(scale,   BigDecimal.ROUND_HALF_UP).doubleValue();
        return String.format("%.2f",f1);
    }
    public static float halfUp(float val,int scale){
        BigDecimal b   =   new   BigDecimal(val);
        float  f1   =   b.setScale(scale,   BigDecimal.ROUND_HALF_UP).floatValue();
        return f1;
    }
    /**
     * 四舍五入,保留两位小数
     * @param val
     * @return
     */
    public static double halfUp(double val){
        return halfUp(val,2);
    }
    /**
     * 四舍五入,保留两位小数
     * @param val
     * @return
             */
    public static float halfUp(float val){
        return halfUp(val,2);
    }

    public static String int2chineseNum(int src) {
        final String num[] = {"零", "一", "二", "三", "四", "五", "六", "七", "八", "九"};
        final String unit[] = {"", "十", "百", "千", "万", "十", "百", "千", "亿", "十", "百", "千"};
        String dst = "";
        int count = 0;
        while (src > 0) {
            dst = (num[src % 10] + unit[count]) + dst;
            src = src / 10;
            count++;
        }
        String str = dst.replaceAll("零[千百十]", "零").replaceAll("零+万", "万")
                .replaceAll("零+亿", "亿").replaceAll("亿万", "亿零")
                .replaceAll("零+", "零").replaceAll("零$", "");
        if (str.equals("二")) {
            str = "两";
        }
        return str;
    }

    public static int getMinimum(int[] a){
        int min = a[0];

        for (int i = 0; i <a.length; i++){
            if(a[i] < min){
                min = a[i];
            }

        }
        return min;
    }


    public static int getMinimum(int[] a,int startIndex,int endIndex){
        if(startIndex>a.length-1){
            return -999;
        }
        int min = a[startIndex];

        for (int i = startIndex+1; i <=endIndex; i++){
            if(a[i] < min){
                min = a[i];
            }

        }
        return min;
    }

    public static double randomNum(float minNum,float maxNum){
        Random random = new Random();
        double randomValue = random.nextDouble() * (maxNum - minNum) + minNum;
        return randomValue;
    }

    public static String uuid(){
        return UUID.randomUUID().toString();
    }
    public static double randomNum2(float maxNum){
        return Math.random()*maxNum;
    }

    public static int randomNum(double maxNum){
        return (int) (Math.random()*maxNum);
    }

    public static void main(String[] args) {
//        double a=halfUp(3.23456);
//        double b=halfUp(3.23556);
//        double c=halfUp(3.2);
//        System.out.println(a);
//        System.out.println(b);
//        System.out.println(c);
//        String detectCreateSql="";
//        detectCreateSql = "CREATE TABLE IF NOT EXISTS detect_record";
//        detectCreateSql += " (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, detect_time TEXT NOT NULL, checker_id TEXT NOT NULL, checker_name TEXT NOT NULL,detect_location TEXT NOT NULL,";
//        detectCreateSql += " plate_number TEXT NOT NULL,plate_color TEXT NOT NULL,truck_photo TEXT,plate_photo TEXT,axle_number INTEGER NOT NULL DEFAULT 0,head_axis_num INTEGER NOT NULL DEFAULT 0,truck_type TEXT NOT NULL DEFAULT '1 - 1',";
//        detectCreateSql += " speed REAL NOT NULL DEFAULT 0.0,weight REAL NOT NULL DEFAULT 0.0,over_weight REAL NOT NULL DEFAULT 0.0,over_weight_rate REAL NOT NULL DEFAULT 0.0,length REAL NOT NULL DEFAULT 0.0,";
//        detectCreateSql += " over_length REAL NOT NULL DEFAULT 0.0, width REAL NOT NULL DEFAULT 0.0, over_width REAL NOT NULL DEFAULT 0.0, height REAL NOT NULL DEFAULT 0.0,";
//        detectCreateSql += " over_height REAL NOT NULL DEFAULT 0.0,uploaded boolean default 0,";
//        detectCreateSql += " axis_over_weight REAL NOT NULL DEFAULT 0.0,axis_over_weight_rate REAL NOT NULL DEFAULT 0.0,";
//        detectCreateSql += " driver TEXT,owner TEXT,detect_type INTEGER default 0,";
//        detectCreateSql += " max_axis_load REAL,";
//        detectCreateSql += " special_tag boolean default 0,limit_weight real default 0.0,license_pic TEXT,sub_wheel INTEGER default 0,sub_wheel_pic TEXT,air_suspension boolean default 0,air_suspension_pic TEXT,";
//        detectCreateSql += " axis_weights TEXT)";
//        System.out.println(detectCreateSql);

//        System.out.println(randomNum2(-2));
//        System.out.println(randomNum2(-2));
//        System.out.println(randomNum2(-2));
//        System.out.println(randomNum2(-2));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        System.out.println(randomNum(-4,4));
//        double a=halfUp(3.47);
//        System.out.println(String.format("%.2f", a));
        double a=halfUp(234.34434,2);
        System.out.println(a);
        String str="2024-08-03 07:30:13";
        System.out.println(uuid());

    }

}
